/*
Disclaimer of Warranty: THE PACKAGE
IS PROVIDED BY THE COPYRIGHT HOLDER
AND CONTRIBUTORS "AS IS' AND WITHOUT
ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR
WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(c) Copyright 2013 Edward Principe
All Rights Reserved
*/
#ifndef ERRREP_H
#define ERRREP_H

#include <Windows.h>
#include <tchar.h>
#include <iostream>
#include <list>
#include <string>
#include <cstdio>
#include <cstring>
#include "syntaxex.h"
#include "errnode.h"
#include "smtptr.h"

using namespace std;

//////////////////////////////////////////////////////////////
// ErrRep: Tracks errors and produces an error report
////////////////////////////////////////////////////////////
class ErrRep
{
public: // Construction
    ErrRep()
    {
        Init();
    }

    ErrRep(const ErrRep& rhs)
    {
        Init();
        Copy(rhs);
    }

public: // Methods
    void Set(SyntaxErr err, unsigned long line, unsigned long col); // Adds an error
    void Set(const ErrNode& errNode);
public: // Methods
    list<ErrNode>::iterator GetFirst();
    list<ErrNode>::iterator GetNext();

    bool IsEnd()
    {
        return _pos == _errNodes.end();

    }
public: // Methods
    void PrintReport(); // Outputs an error report

public: // Accessor methods
    list<ErrNode> GetErrorList() {return _errNodes;}
    unsigned long GetErrorCount() const {return _errors;}
    unsigned long GetWarningCount() const {return _warnings;}

public: // Operators
    ErrRep& operator = (const ErrRep& rhs)
    {
        Copy(rhs);
        return *this;
    }

    ErrRep& operator = (const ErrNode& rhs)
    {
        // Reset
        _errNodes.erase(_errNodes.begin(), _errNodes.end());
        _errors = 0;
        _warnings = 0;

        // Add error
        Set(rhs);

        return *this;

    }

    ErrRep& operator += (const ErrRep& rhs)
    {
        Append(rhs);
        return *this;

    }

    ErrRep& operator += (const ErrNode& rhs)
    {
        Append(rhs);
        return *this;
    }

    ErrRep& operator + (const ErrRep& rhs)
    {
        Append(rhs);
        return *this;
    }

    ErrRep& operator + (const ErrNode& rhs)
    {

        Append(rhs);
        return *this;

    }

private: // Methods
    void Append(const ErrRep& rhs);
    void Append(const ErrNode& rhs);

private: // Methods
    void Init()
    {
        _errors = 0;
        _warnings = 0;
    }

    void Copy(const ErrRep& rhs); // Copies the class
private: // Attributes
    list<ErrNode> _errNodes; // The error
    list<ErrNode>::iterator _pos; // The position pointing to in the error list
    unsigned long _errors; // Error count
    unsigned long _warnings; // Warning count
};
#endif // ERRREP_H
